package game.worlds;

import hx.utils.SceneManager;
import game.views.RoleLogView;
import game.views.FightStateView;

/**
 * 1V1战斗场景
 */
class PK1V1World extends Game1V1BaseWorld {
	override function restart() {
		#if game
		var state:FightStateView = cast this.state;
		if (state.p1.winTimes >= 2 || state.p2.winTimes >= 2) {
			// 战斗结算
			var view = new RoleLogView({
				winState: state.p1.winTimes > state.p2.winTimes ? WIN : LOSE,
				winTimes: state.p1.winTimes,
				data: [
					{
						id: state.p1.role.roleid,
						data: gameFightAnalysisLogData.getData(1, state.p1.role.roleid)
					}
				]
			}, {
				winState: state.p1.winTimes < state.p2.winTimes ? WIN : LOSE,
				winTimes: state.p2.winTimes,
				data: [
					{
						id: state.p2.role.roleid,
						data: gameFightAnalysisLogData.getData(2, state.p2.role.roleid)
					}
				]
			});
			SceneManager.getInstance().replaceScene(view, true);
			return;
		} else {
			// 记录战斗结果
			gameFightAnalysisLogData.pushData(1, state.p1.role.roleid, state.p1.role.fightAnalysisData);
			gameFightAnalysisLogData.pushData(2, state.p2.role.roleid, state.p2.role.fightAnalysisData);
		}
		super.restart();
		cast(state, game.views.FightStateView).restart();
		#end
	}
}
